<?php
/*==========================================================================*\
| AGRIVIET - CONTENT MANAGERMENT SYSTEM						
\*==========================================================================*/

	//Xoa nhieu fan tu cung 1 luc
	if (isset($_POST['ButDel'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("delete from mail where id='".$id."'");
				if ($result) {
					$cnt++;		

			}
		}
		echo "<script>window.location='./?act=mail</script>";
	}
	
	//Unpub
	if (isset($_POST['Unp'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("UPDATE mail set published='0' where id='".$id."'");
				if ($result) {
					$cnt++;		

			}
		}
		echo "<script>window.location='./?act=mail&code=1</script>";
	}
	
	//Chuyen tin tuc qua danh muc khac
	if (isset($_POST['move'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("UPDATE mail set catid=".$_POST['catid']." where id='".$id."'");
				if ($result) {
					$cnt++;		
			}
		}
		echo "<script>window.location='./?act=mail'</script>";
	}
				
	//Empty table
	if (isset($_POST['DelAll'])) {
		mysql_query("TRUNCATE TABLE mail");
		echo "<script>window.location='./?act=mail'</script>";
	}
		
 if($_GET['code']==1) echo '<div class="blue">Đã cập nhật thành công</div>'; ?>
<form method="POST" name="frmList" action="index.php">
<table border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#D5E2FF" width="100%" id="AutoNumber1">
  <tr>
    <td height="25" colspan="6" align=left class="xtitle">mail</td>
    </tr>
  <tr>
    <td align=center class="title"><input type="checkbox" name="chkall" onclick="chkallClick(this);"></td>
    <td align="center" nowrap class="title"><b>id</b></td>
    <td align=left class="title" >Name</td>
    <td align="center" nowrap class="title">email</td>
    <td align="center" nowrap class="title">Mess</td>
    <td align="center" nowrap class="title">Date</td>
    </tr>
<?php
	//if($_GET['catid']!='') $where = 'catid='.$_GET['catid'];
	//else $where ='1=1';
	$sql="select * from mail order by date DESC";
	$result=mysql_query($sql);
	$total_records=mysql_num_rows($result);
	$record_per_page=10;
	$scroll=5;
	$page=new Page(); ///creating new instance of Class Page
	$page->set_page_data($urllink,$total_records,$record_per_page,$scroll,true,true,true);
	$page->set_qry_string();
	if($result=mysql_query($page->get_limit_query($sql))){
	$i=0;
	while($row=mysql_fetch_object($result)){
	$i++;
	if ($i%2) $class="le"; else $class="chan";
?>
  <tr class="<?=$class;?>">
    <td align="center">

    <input type="checkbox" name="chk[]" value="<? echo $row->id; ?>"></td>
    <td align="center" valign="top" class="<?=$class;?>"><? echo $row->id; ?>&nbsp;</td>

    <td align="left" valign="top" >
	<a href="index.php?act=<?=$_GET['act'];?>_m&id=<? echo $row->id; ?>&catid=<?=$_GET['catid'];?>">
	<b><? echo $row->name; ?></b></a></td>

    <td align="center" valign="top" style="overflow: hidden">
	<a target="_blank" href="../<? echo $row->image; ?>"><? echo $row->email; ?></a></td>
    <td align="center" ><textarea cols="80" rows="10"><? echo $row->mess; ?></textarea></td>
    <td align="center" valign="top" ><? echo $row->date; ?></td>
    </tr>

  <?
	}
}
  ?>
</table>

<input type="hidden" name="act" value="mail">

<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
	<tr>
	  <td>

<input type="submit" value="Delete" name="ButDel" onclick="return confirm('B&#7841;n có ch&#7855;c ch&#7855;n mu&#7889;n xoá ?');" class="button">
<input type="submit" value="Empty" name="DelAll" onclick="return confirm('Do you really want to delete all records?');" class="button">&nbsp;</td>
	  <td align="right"><div id="pagenav"><?=$page->get_page_nav();?></div></td>
	</tr>
	<tr>
	  <td colspan="2">&nbsp;</td>
    </tr>
</table>
</form>	  